/** 冷凝水管坡度枚举
 *
 */
export enum Slop {
  "1‰" = "0.001",
  "3‰" = "0.003",
}
const pipeDN = [
  "DN20",
  "DN25",
  "DN32",
  "DN40",
  "DN50",
  "DN80",
  "DN100",
  "DN125",
  "DN150",
];
const minSlop = [7, 17.6, 100, 176, 598, 1055, 1512, 12462, 30000];
const maxSlop = [17, 42, 230, 400, 1100, 2000, 3500, 15000, 40000];

/** 根据制冷量选择冷凝水管管径；
 *
 * @param refrigerationCapacity 制冷量，单位：Kw;
 * @param slop 冷凝水管坡度枚举
 * @returns 水管公称直径，string
 */
export const selectPipe = (
  refrigerationCapacity: number,
  slop = Slop["1‰"]
) => {
  let slopArr: Array<number>;
  switch (slop) {
    case Slop["1‰"]:
      slopArr = minSlop;
      break;
    case Slop["3‰"]:
      slopArr = maxSlop;
      break;
    default:
      slopArr = minSlop;
      break;
  }
  if (refrigerationCapacity >= slopArr[slopArr.length - 1])
    throw new Error(
      "Parameter exception, The value should be less than 30000!!"
    );

  let dn: string = "";
  for (let i = 0; i < slopArr.length - 1; i++) {
    if (
      refrigerationCapacity >= slopArr[i] &&
      refrigerationCapacity < slopArr[i + 1]
    ) {
      dn = pipeDN[i + 1];
      break;
    }
  }
  return dn ? dn : (dn = pipeDN[0]);
};
